package com.wry.controller;

import com.wry.service.DataImportService;
import com.wry.service.TemplateService;
import com.wry.service.XxxService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * <h1>  <h1>
 *
 * @author 魏如元
 * @since 2022/9/6
 */
@RestController
@RequestMapping("import")
public class ImportController {

    @Resource
    private DataImportService importService;

    @Resource
    private XxxService xxxService;

    @Resource
    private TemplateService templateService;

    /**
     * 模板下载
     *
     * @param response 响应实体
     */
    @GetMapping("template/download")
    public void templateDownload(HttpServletResponse response) throws IOException {
        importService.templateDownload(response);
    }

    /**
     * 导入
     */
    @PostMapping
    public String importGoods(@RequestParam("file") MultipartFile importGoods) throws IOException {
        return importService.importGoods(importGoods);
    }

    /**
     * 导出
     */
    @GetMapping("template")
    public void templateImport(HttpServletResponse response) throws IOException {
        templateService.templateImport(response);
    }

    /**
     * 导入
     */
    @PostMapping("import-express")
    public void importExpress(@RequestParam("file") MultipartFile file, HttpServletResponse response) throws IOException {
        importService.importExpress(file, response);
    }
}
